require('./index.css');
var _mm = require('util/mm.js');
var _productService = require('service/product.js');
var listTpl = require('./index.tpl');

require('util/pagination/index.js');
require('util/layer/index.js');

		layer.msg('加载中', {
			icon: 16,
			shade: 0.01
		});
layer.close();

var list = {
	init: function() {
		this.getData();
	},
	getData: function() {
		var _this = this;
		var pageNum = _mm.getUrlParam('pageNum');
		var pageSize = _mm.getUrlParam('pageSize');
		var orderBy = _mm.getUrlParam('orderBy');
		var categoryId = _mm.getUrlParam('categoryId');

		var data = {
			pageNum: pageNum || 1,
			pageSize: pageSize || 2, //每页显示多少条
			orderBy: orderBy || 'default',
			categoryId: categoryId
		}


		_productService.list(data).done(function(res) {
			if (res.status == 0) {
				_this.setHtml(res.data);
				if (res.data) {
					$("#pagination").pagination({
						currentPage: 1,
						totalPage: res.data.pages, //共多少页
						isShow: true,
						count: res.data.size, //每页显示多少条
						homePageText: "首页",
						endPageText: "尾页",
						prevPageText: "上一页",
						nextPageText: "下一页",
						callback: function(current) {
							data.pageNum = current;
							_productService.list(data).done(function(resData) {
								_this.setHtml(resData.data);
							});
						}
					});
				}
			}
		});
	},
	setHtml: function(data) {
		var listHtml = listTpl({
			data: data
		});
		$('#product-list').html(listHtml);
	}
}

$(function() {
	list.init();
});